﻿using System;

namespace Ue.CQRS.Results
{
    public class ResultFactory
    {
        public static IResult Build(EventAttribute eventAttribute,dynamic resultOrEventArgs)
        {
            if (resultOrEventArgs is IResult)
            {
                return (IResult)resultOrEventArgs;
            }

            return ResultFactory.BuildSyncResult(resultOrEventArgs);
            

            //var resultType = resultOrEventArgs.GetType();
            //if (resultType.GetInterface("IResult") != null)
            //{
            //    return (IResult)resultOrEventArgs;
            //}

            //resultType = typeof(SyncResult<>).MakeGenericType(resultType);

            //return Activator.CreateInstance(resultType, resultOrEventArgs) as IResult;
        }

        private static SyncResult<T> BuildSyncResult<T>(T eventArgs)
        {
            return new SyncResult<T>(eventArgs);
        }
    }
}
